/**

#include "HttpUtil.h"
#include <QCoreApplication>
#include <QDebug>
#include <QThread>

// 获取单例实例
HttpUtil& http = HttpUtil::instance();

// GET请求示例
http.get("/login/info",
    [](const nlohmann::json& response) {
        qDebug() << "GET success:" << QString::fromStdString(response.dump());
    },
    [](const QString& error) {
        qDebug() << "GET error:" << error;
    },
    {{"Authorization", "Bearer token123"}}
);

// POST请求示例
nlohmann::json postData = {
    {"name", "John Doe"},
    {"age", 30}
};

http.post("/getUser", postData,
    [](const nlohmann::json& response) {
        qDebug() << "POST success:" << QString::fromStdString(response.dump());
    },
    [](const QString& error) {
        qDebug() << "POST error:" << error;
    }
);

// 测试登录
void testLogin() {
    qDebug() << "\n=== 测试登录 ===";

    json loginData = {
        {"username", "admin"},
        {"password", "123456"}
    };

    HttpUtil::getInstance()->post(
        "/login",
        loginData,
        [](const json& response) {
            if (response["success"].get<bool>()) {
                qDebug() << "登录成功:";
                qDebug() << "Token:" << QString::fromStdString(response["token"].get<std::string>());

                // 保存token到全局请求头
                HttpUtil::getInstance()->setGlobalHeaders({
                    {"Authorization", "Bearer " + QString::fromStdString(response["token"].get<std::string>())}
                });

                // 登录成功后获取用户信息
                testGetUserInfo();
            } else {
                qDebug() << "登录失败:" << QString::fromStdString(response["error"].get<std::string>());
            }
        },
        [](const QString& error) {
            qDebug() << "登录请求失败:" << error;
        }
    );
}

// 测试获取用户信息
void testGetUserInfo() {
    qDebug() << "\n=== 测试获取用户信息 ===";

    HttpUtil::getInstance()->get(
        "/user/info",
        [](const json& response) {
            qDebug() << "获取用户信息成功:";
            qDebug() << "用户ID:" << QString::fromStdString(response["userId"].get<std::string>());
            qDebug() << "用户名:" << QString::fromStdString(response["username"].get<std::string>());
            qDebug() << "角色:" << QString::fromStdString(response["role"].get<std::string>());

            // 获取用户信息后更新设备状态
            testUpdateDeviceStatus();
        },
        [](const QString& error) {
            qDebug() << "获取用户信息失败:" << error;
        },
        {{"id", "user123"}}
    );
}

// 测试更新设备状态
void testUpdateDeviceStatus() {
    qDebug() << "\n=== 测试更新设备状态 ===";

    json deviceData = {
        {"deviceId", "device123"},
        {"status", "online"},
        {"data", {
            {"temperature", 25.5},
            {"humidity", 60.0}
        }}
    };

    HttpUtil::getInstance()->post(
        "/device/update",
        deviceData,
        [](const json& response) {
            if (response["success"].get<bool>()) {
                qDebug() << "更新设备状态成功:";
                qDebug() << "设备ID:" << QString::fromStdString(response["deviceId"].get<std::string>());
                qDebug() << "更新时间:" << QString::fromStdString(response["updateTime"].get<std::string>());

                // 更新设备状态后获取设备数据
                testGetDeviceData();
            } else {
                qDebug() << "更新设备状态失败:" << QString::fromStdString(response["error"].get<std::string>());
            }
        },
        [](const QString& error) {
            qDebug() << "更新设备状态请求失败:" << error;
        }
    );
}

// 测试获取设备数据
void testGetDeviceData() {
    qDebug() << "\n=== 测试获取设备数据 ===";

    HttpUtil::getInstance()->get(
        "/device/data",
        [](const json& response) {
            qDebug() << "获取设备数据成功:";
            qDebug() << "设备ID:" << QString::fromStdString(response["deviceId"].get<std::string>());
            qDebug() << "数据类型:" << QString::fromStdString(response["type"].get<std::string>());
            qDebug() << "数据值:" << QString::fromStdString(response["values"].dump());
            qDebug() << "时间戳:" << QString::fromStdString(response["timestamp"].get<std::string>());

            // 获取设备数据后设置报警
            testSetAlarm();
        },
        [](const QString& error) {
            qDebug() << "获取设备数据失败:" << error;
        },
        {{"deviceId", "device123"}, {"type", "temperature"}}
    );
}

// 测试设置报警
void testSetAlarm() {
    qDebug() << "\n=== 测试设置报警 ===";

    json alarmData = {
        {"deviceId", "device123"},
        {"type", "temperature"},
        {"threshold", 30.0},
        {"condition", ">"},
        {"notify", {
            {"email", "admin@example.com"},
            {"phone", "13800138000"}
        }}
    };

    HttpUtil::getInstance()->post(
        "/alarm/set",
        alarmData,
        [](const json& response) {
            if (response["success"].get<bool>()) {
                qDebug() << "设置报警成功:";
                qDebug() << "报警ID:" << QString::fromStdString(response["alarmId"].get<std::string>());
                qDebug() << "设备ID:" << QString::fromStdString(response["deviceId"].get<std::string>());
                qDebug() << "创建时间:" << QString::fromStdString(response["createTime"].get<std::string>());
            } else {
                qDebug() << "设置报警失败:" << QString::fromStdString(response["error"].get<std::string>());
            }
        },
        [](const QString& error) {
            qDebug() << "设置报警请求失败:" << error;
        }
    );
}

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    // 开始测试流程
    testLogin();

    // 等待异步请求完成
    QThread::msleep(5000);

    return app.exec();
}

*/